package com.easytext.service.coleman;

import com.easytext.service.api.Analyzer;

import java.util.List;

/**
 * @author caifan
 * @created 2021/11/28
 * @description:
 */
public class Coleman implements Analyzer {

    public static final String NAME = "Coleman-Liau";

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public double analyze(List<List<String>> text) {
        float totalsentences = text.size();
        float words = text.stream().mapToInt(sentence -> sentence.size()).sum();
        float letters = text.stream().flatMapToInt(sentence -> sentence.stream().mapToInt(word -> word.length())).sum();

        return 0.0588 * (letters / (words / 100)) - 0.296 * (totalsentences / (words / 100)) - 15.8;
    }
}
